package com.topvision.myviewtest.mvp.demo3;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.topvision.myviewtest.R;
import com.topvision.myviewtest.mvp.bean.WeatherBean;
import com.topvision.myviewtest.mvp.demo3.base.AbstractMvpActivity;
import com.topvision.myviewtest.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: lucy
 * Date: 2017-12-11 10:16
 * 1.Activity需要实现v层接口
 * 2.Persenter需要持有v层引用和m层引用
 * 3.在实现类view中创建persenter
 */

public class MainActivityDemo_3 extends AbstractMvpActivity<RequestView3,RequestPresenter3> implements RequestView3 {

    private final String TAG = this.getClass().getSimpleName();

    @BindView(R.id.tv_mvp_study)
    TextView mTvMvpStudy;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvp_study);
        ButterKnife.bind(this);
    }

    @Override
    protected RequestPresenter3 createPresenter() {
        return new RequestPresenter3();
    }

    public void request(View view) {
        getPresenter().clickRequest("101010100");
    }

    @Override
    public void requestLoading() {
        ToastUtils.showToast(getApplicationContext(), "正在加载...");
    }

    @Override
    public void requestSuccess(WeatherBean result) {
        mTvMvpStudy.setText(result.getWeatherinfo().toString());
    }

    @Override
    public void requestFailure(String result) {
        mTvMvpStudy.setText(result);
    }
}
